package cn.donting.jme.edit.ui.toolbar;

import cn.donting.jme.edit.annotation.NotNull;
import cn.donting.jme.edit.annotation.Nullable;
import cn.donting.jme.edit.event.EventListener;
import cn.donting.jme.edit.event.EventManager;
import cn.donting.jme.edit.event.SelectSpatialEvent;
import com.jme3.asset.AssetManager;
import com.jme3.input.InputManager;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

import javafx.scene.control.ToggleButton;

public abstract class ToolBar extends ToggleButton implements EventListener<SelectSpatialEvent> {

    public ToolBar() {
        EventManager.registerListener(SelectSpatialEvent.class, this);
    }


    public abstract void init(AssetManager assetManager, InputManager inputManager);

    /**
     * 选中Spatial并且激活 时触发
     *
     * @param spatial NUllBle
     */
    public abstract void selectSpatial(@Nullable Spatial spatial);

    @Override
    public void event(SelectSpatialEvent event) {
        if (selectedProperty().get()) {
            selectSpatial(event.getSpatial());
        }
    }

    /**
     * 操作节点 需要返回唯一的节点
     * @return
     */
    public abstract @NotNull Node getJmeControlNode();
}
